<template>
  <up-popup :show="show" mode="bottom" :round="10" @close="close" @open="open">
    <view class="p-20" style="display: flex;padding-bottom: 60rpx">
      <view class="flex-column-center" style="margin-right: 30rpx" @click="share('WXSceneSession')">
        <image src="/static/icon/common/weixin.png" style="width: 80rpx;height: 80rpx;"/>
        <view class="u-f-sm mt-10">微信</view>
      </view>
      <view class="flex-column-center" @click="share('WXSceneTimeline')">
        <image src="/static/icon/common/pyq.png" style="width: 80rpx;height: 80rpx"/>
        <view class="u-f-sm mt-10">朋友圈</view>
      </view>
    </view>
  </up-popup>
</template>

<script lang="ts" setup>
import {ref, defineExpose, defineProps} from "vue";
import {SHARE_OBJ} from "@/util/objOptions";

const props = defineProps({
  shareData: {
    type: Object,
    default: () => {
      return {...SHARE_OBJ}
    }
  }
})

const show = ref(false)

const share = (scene: string) => {
  uni.showLoading({
    title: "正在打开微信...",
    mask: true
  })
  uni.share({
    provider: "weixin",
    scene: scene,
    type: 0,
    href: props.shareData.href,
    title: props.shareData.title,
    summary: props.shareData.desc,
    imageUrl: props.shareData.imgUrl,
    success: function (res) {
      console.log("success:" + JSON.stringify(res));
    },
    fail: function (err) {
      console.log("fail:" + err.errMsg);
      uni.showToast({
        title: "分享失败",
        icon: "none"
      })
    },
    complete: function () {
      uni.hideLoading()
    }
  })
}

const open = () => {
  console.log("open")
  show.value = true
}

const close = () => {
  console.log("close")
  show.value = false
}

defineExpose({
  open
})

</script>

<style scoped lang="scss">
@import "@/static/css/index.css";
</style>